<template>
	<view class="store">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				商品管理
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="top clearfix">
				<view class="left fl clearfix">
					<view class="mess fl">
						<view :class="[attrIndex==1?'active':'']" @click="zhiying(1)">直营商品</view>
						<text class="dian" v-if="attrIndex == 1"></text>
					</view>
					<view class="mess mess1 fl" @click="zhiying(2)" v-if="attrIf">
						<view :class="[attrIndex==2?'active':'']">团队商品</view>
						<text class="dian" v-if="attrIndex == 2"></text>
					</view>
				</view>
				<view class="right fr clearfix" @click="topage('/subpackageA/goods/add')">
					<image :src="baseUrl + '/wximage/add.png'" class="fl"></image>
					<view class="name fl">新增</view>
				</view>
			</view>
			<view class="sousuo clearfix">
				<input type="text" placeholder="请输入关键字" v-model="formData.search" @confirm="searchc()" />
				<image :src="baseUrl + '/wximage/sousuo.png'" @click="searchc()"></image>
			</view>
		</view>
		<view class="shuju" v-if="goodsList.length != 0">
			<view class="li" @click="topage('/subpackageA/goods/add?id='+item.id)"
				v-for="(item,index) in goodsList" :key="index">
				<view class="top clearfix">
					<image :src="item.sitepicture" class="fl"></image>
					<view class="cen fl">
						<text class="title">{{item.name}}</text>
						<text class="shebei">单价：{{item.danjia}}</text>
						<text class="shebei">成本价：{{item.costprice}}</text>
						<text class="time" v-if="item.charger_agents_name==null||item.charger_agents_name==''">所属：平台</text>
						<text class="time" v-else>所属代理商：{{item.charger_agents_name}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				attrIndex: 1,
				formData: {
					agent_id: uni.getStorageSync('agent_id'),
					page: 1,
					pageSize: 10,
					search: '',
					role_id: uni.getStorageSync('role_id'),
					attrIndex: 1,
					total: 0,
				},
				goodsList: [],
				attrIf: false,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
		},
		onShow() {
			if (uni.getStorageSync('role_id') == 13) {
				this.attrIf = false;
			} else {
				this.attrIf = true;
			}
			
			this.goodsList = [];
			this.formData.page = 1;
			this.formData.search = '';
			
			this.getGoodslist();
		},
		onReachBottom() {
			if(this.goodsList.length != this.formData.total){
				this.formData.page = this.formData.page+1;
				this.getGoodslist();
			}
		},
		methods: {
			searchc() {
				this.goodsList = [];
				this.formData.page = 1;

				this.getGoodslist();
			},
			zhiying(e) {
				this.attrIndex = e;
				this.goodsList = [];
				this.formData.attrIndex = this.attrIndex;
				this.formData.page = 1;
				this.formData.search = '';

				this.getGoodslist();
			},
			getGoodslist() {
				this.request({
					url: '/xcx/goodslist',
					data: this.formData,
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.formData.total = res.data.data.total;
						this.goodsList = this.goodsList.concat(res.data.data.data);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			},
			fanhui() {
				uni.navigateBack();
			},
			topage(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f9f9ff;
	}

	.store {
		width: 100%;
		margin: 0 auto;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;

			.top {
				.left {
					.mess {
						height: 48rpx;
						line-height: 48rpx;
						text-align: center;

						view {
							font-size: 24rpx;
							color: #333333;
						}

						.dian {
							width: 8rpx;
							height: 8rpx;
							background: #5C88FA;
							display: block;
							border-radius: 50%;
							margin: 0 auto;
						}

						.active {
							font-size: 32rpx;
							color: #333333;
							font-weight: 700;
							margin-left: 0;
						}
					}

					.mess1 {
						margin-left: 20rpx;
					}
				}

				.right {
					width: 116rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;
					margin-top: 6rpx;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-left: 10rpx;
						margin-right: 6rpx;
					}

					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
			}

			.sousuo {
				width: 100%;
				box-sizing: border-box;
				position: relative;
				margin-top: 30rpx;

				input {
					width: 100%;
					height: 60rpx;
					line-height: 60rpx;
					background: #ffffff;
					border-radius: 30rpx;
					padding-left: 30rpx;
					color: #999999;
					box-sizing: border-box;
				}

				image {
					width: 72rpx;
					height: 40rpx;
					position: absolute;
					right: 10rpx;
					top: 10rpx;
					z-index: 10;
				}
			}

			.bottom {
				margin-top: 14rpx;

				.left {
					width: 116rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #E6E9FF;
					border-radius: 24rpx;
					margin-top: 6rpx;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-left: 10rpx;
						margin-right: 6rpx;
					}

					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}

				.right {
					width: 262rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;
					margin-top: 6rpx;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-left: 10rpx;
						margin-right: 6rpx;
					}

					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}

		.shuju {
			width: 100%;
			padding: 30rpx 20rpx;
			box-sizing: border-box;
			margin-top: -140rpx;

			.li {
				width: 100%;
				position: relative;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 30rpx 28rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;

				image {
					width: 150rpx;
					height: 150rpx;
				}

				.cen {
					width: 390rpx;
					margin-left: 20rpx;

					text {
						display: block;
					}

					.title {
						font-size: 28rpx;
						color: #333333;
						font-weight: 700;
						margin-bottom: 8rpx;
					}

					.shebei {
						font-size: 22rpx;
						color: #3B91F8;
					}

					.time {
						font-size: 24rpx;
						color: #999999;
						line-height: 36rpx;
					}
				}

				.you {
					position: absolute;
					top: 30rpx;
					right: 30rpx;
					font-size: 28rpx;
					font-weight: 700;
				}

				.zhuangtai {
					color: #FA5E5C;
				}

				.zhuangtai1 {
					color: #3B91F8;
				}

				.zhuangtai2 {
					color: #999999;
				}

				.address {
					margin-top: 10rpx;

					image {
						width: 30rpx;
						height: 30rpx;
						margin-top: 4rpx;
					}

					text {
						display: inline-block;
						line-height: 32rpx;
						font-size: 24rpx;
						color: #666666;
						width: 90%;
					}
				}

				.addressts {

					text {
						// width: 62%;
					}
				}

				.bili {
					position: absolute;
					right: 28rpx;
					bottom: 30rpx;
					width: 180rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					background: #3B91F8;
					color: #FFFFFF;
					border-radius: 16rpx;
					font-size: 28rpx;
				}
			}
		}

		.empty {
			width: 100%;
			margin: 200rpx auto 0;
			text-align: center;

			image {
				width: 390rpx;
				height: 340rpx;
			}

			text {
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}

		.morebeijing {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 100vh;
			background: #000000;
			opacity: 0.5;
			z-index: 100;
		}

		.moretankuang {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 450rpx;
			background: #fff;
			z-index: 200;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			padding: 20rpx 0;

			.bankuai {

				.top {
					background: #FDFDFD;
					font-size: 32rpx;
					color: #333333;
					height: 72rpx;
					line-height: 72rpx;
					padding-left: 40rpx;
					box-sizing: border-box;
					border-bottom: 1rpx solid #DFE6FF;
					position: relative;

					.chongzhi {
						position: absolute;
						top: 8rpx;
						right: 40rpx;
						width: 136rpx;
						height: 48rpx;
						line-height: 48rpx;
						text-align: center;
						border-radius: 16rpx;
						color: #333333;
						background: #E3F2FF;
						font-size: 24rpx;
					}

				}

				.time {
					margin-top: 20rpx;
					margin-left: 40rpx;
					font-size: 24rpx;
					color: #333333;

					text:nth-of-type(1) {
						font-size: 24rpx;
						color: #FA5E5C;
					}

					text:nth-of-type(2) {
						font-size: 24rpx;
						color: #5C88FA;
					}
				}

				.bottom {
					margin-top: 40rpx;
					margin-bottom: 50rpx;

					text {
						display: inline-block;
						margin-left: 60rpx;
						width: 160rpx;
						height: 54rpx;
						text-align: center;
						border-radius: 16rpx;
						line-height: 54rpx;
						background: #F6F6F6;
						font-size: 24rpx;
						color: #333333;
					}

					.active {
						background: #E3F2FF;
					}
				}

				.shurubottom {
					margin-top: 20rpx;
					margin-bottom: 50rpx;
					width: 100%;
					padding: 0 40rpx;

					.tishi {
						font-size: 24rpx;
						color: #333333;
					}

					.shuru {
						width: 60%;
						margin: 0 auto;
						text-align: center;
						height: 50rpx;
						line-height: 50rpx;
						margin-top: 40rpx;

						input {
							width: 33.3%;
							text-align: center;
							height: 50rpx;
							line-height: 50rpx;
							color: #3B91F8;
							border-bottom: 1rpx solid #E3F2FF;
						}

						text {
							display: inline-block;
							width: 33.3%;
						}
					}
				}
			}

			.queren {
				width: 180rpx;
				margin: 0 auto;
				height: 60rpx;
				line-height: 60rpx;
				border-radius: 16rpx;
				text-align: center;
				background: #3B91F8;
				margin-top: 100rpx;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}
</style>